<?php
/**
 * Author:xsc
 * Time:2023/8/31 10:43
 */

namespace App\Repository;

use App\Models\Config;

class ConfigRepo extends BaseRepo
{

    /**
     * 查询配置
     * @param string $name
     * @return array
     * Author:xsc
     * Time:2023/8/31 11:31
     */
    public function getConfig(string $name)
    {
        $fields = ['name', 'title', 'remark', 'value'];
        $res = Config::query()->where('name', $name)->first($fields);
        return $res ? $res->toArray() : [];
    }

    /**
     * 查询配置值
     * @param string $name
     * @return mixed|string
     * Author:xsc
     * Time:2023/8/31 16:48
     */
    public function getConfigValue(string $name)
    {
        $res = Config::query()->where('name', $name)->first('value');
        $res = $res ? $res->toArray() : [];

        if (isset($res['value'])) {
            return $res['value'];
        }
        return '';
    }

}
